package com.hangsu.train.common.point;

import lombok.Data;

import java.util.List;

/**
 * @author lyy
 * @Date 2024/6/8
 */
@Data
public class F3D {

    private double confidence;

    private String poseName;

    private int poseType;

    private List<Point> poses;

    public static double getKneeCurvatureAngle(F3D pose) {
        if (pose == null) {
            return 0.0;
        }
        Point pose1, pose2, pose3;

        try {
            double z1 = pose.poses.get(25).getZ();
            double z2 = pose.poses.get(26).getZ();
            int comparison = Double.compare(z1, z2);
            if (comparison > 0) {
                pose1 = pose.poses.get(23);
                pose2 = pose.poses.get(25);
                pose3 = pose.poses.get(27);
            } else {
                pose1 = pose.poses.get(24);
                pose2 = pose.poses.get(26);
                pose3 = pose.poses.get(28);
            }
            return findAngle(pose1, pose2, pose3);
        } catch (Exception e) {
            return 0.0;
        }
    }


    public static double findAngle(Point pose1, Point pose2, Point pose3) {
        if (pose1 == null || pose2 == null || pose3 == null) {
            return 0;
        }
        float x1 = pose1.getX();
        float x2 = pose2.getX();
        float x3 = pose3.getX();
        float y1 = pose1.getY();
        float y2 = pose2.getY();
        float y3 = pose3.getY();
        return Math.toDegrees(Math.atan2(y3 - y2, x3 - x2) - Math.atan2(y1 - y2, x1 - x2));
    }
}